var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var cors = require('cors')
require('./database/connect')  //引入数据库连接文件
var { checkToken } = require('./utils/auth-token')

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var stuRouter = require('./routes/stu');
var accountRouter = require('./routes/account');
var postorderRouter = require('./routes/postorder')

var app = express();
app.use(cors())  //处理服务端接口跨域问题
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/stu', (req, res, next) => { checkToken(req, res, next) }, stuRouter);
app.use('/account', (req, res, next) => { checkToken(req, res, next) }, accountRouter); //这个路由模块需要token验证后访问
app.use('/postorder', postorderRouter)
app.use('/', postorderRouter)
module.exports = app;
